package com.example.lenovo.demo.presenter.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lenovo.demo.R;
import com.example.lenovo.demo.model.databean.CityBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Lenovo on 2017/1/8.
 */

public class City_Hot_LvAdapter extends BaseAdapter {
    private List<CityBean.DataBean.SectionsBean.ModelsBean> data;
    private Context context;

    public City_Hot_LvAdapter(List<CityBean.DataBean.SectionsBean.ModelsBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view==null){
            viewHolder=new ViewHolder();
            view= LayoutInflater.from(context).inflate(R.layout.city_hot_lvitem,viewGroup,false);
            viewHolder.tv1= (TextView) view.findViewById(R.id.city_hot_item_tv1);
            viewHolder.tv2= (TextView) view.findViewById(R.id.city_hot_item_tv2);
            viewHolder.imageView= (ImageView) view.findViewById(R.id.city_hot_item_img);
            view.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) view.getTag();
        }
        CityBean.DataBean.SectionsBean.ModelsBean modelsBean=data.get(i);
        viewHolder.tv1.setText(modelsBean.getTitle());
        viewHolder.tv2.setText(modelsBean.getSummary());
        viewHolder.imageView.setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
        Picasso.with(context).load(modelsBean.getPhoto_url()).into(viewHolder.imageView);
        return view;
    }
    class ViewHolder{
        ImageView imageView;
        TextView tv1,tv2;
    }
}
